package com.guigu.tms.base.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.tms.base.mapper.PdTransportLineTypeMapper;
import com.guigu.tms.base.service.IPdTransportLineTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guigu.tms.commons.entity.base.PdTransportLineType;
import com.guigu.tms.commons.entity.base.VehicleManagement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Random;

/**
 * <p>
 * 线路类型表 服务实现类
 * </p>
 *
 * @author wj
 * @since 2022-09-26
 */
@Service
public class PdTransportLineTypeServiceImpl extends ServiceImpl<PdTransportLineTypeMapper, PdTransportLineType> implements IPdTransportLineTypeService {

    @Autowired
    PdTransportLineTypeMapper pdTransportLineTypeMapper;

    @Override
    public PageInfo<PdTransportLineType> findTransportLineTypeList(@RequestBody Map<String, String> map) {
        String pageindex=map.get("pageindex");
        String pagenum=map.get("pagenum");
        int page=Integer.valueOf(pageindex)<=0?1:Integer.valueOf(pageindex);
        PageHelper.startPage(page,Integer.valueOf(pagenum));
        List<PdTransportLineType> pdTrucks = pdTransportLineTypeMapper.findTransportLineType(map);
        return new PageInfo<>(pdTrucks);
    }

    @Override
    public int AddTransportLineType(PdTransportLineType pdTransportLineType) {
            SimpleDateFormat simpleDateFormat;
            simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
            Date date = new Date();
            String str = simpleDateFormat.format(date);
            Random random = new Random();
            int rannum = (int) (random.nextDouble() * (999 - 100 + 1)) + 100;
            String s=str+rannum;
            pdTransportLineType.setId(s);
            pdTransportLineType.setUpdater("admin");
            pdTransportLineType.setLastUpdateTime(LocalDateTime.now());
            return pdTransportLineTypeMapper.insert(pdTransportLineType);
    }

    @Override
    public int UpdateTransportLineType(PdTransportLineType pdTransportLineType) {
        pdTransportLineType.setUpdater("root");
        pdTransportLineType.setLastUpdateTime(LocalDateTime.now());
        return pdTransportLineTypeMapper.updateById(pdTransportLineType);
    }

    @Override
    public int DeleteTransportLineTypeByid(String id) {
        return pdTransportLineTypeMapper.deleteById(Integer.valueOf(id));
    }
}
